package client;

public class ManaPool {

	public ManaCost[] pool = new ManaCost[5];

	public ManaPool() {
		ManaCost black = new ManaCost(MagicColor.BLACK, 0);
		ManaCost green = new ManaCost(MagicColor.GREEN, 0);
		ManaCost red = new ManaCost(MagicColor.RED, 0);
		ManaCost white = new ManaCost(MagicColor.WHITE, 0);
		ManaCost blue = new ManaCost(MagicColor.BLUE, 0);
		pool[0] = black;
		pool[1] = green;
		pool[2] = red;
		pool[3] = white;
		pool[4] = blue;
	}

	public int getColor(MagicColor color) {
		int mana = 0;
		if (color.equals(MagicColor.BLACK)) {
			mana = pool[0].amount;
		} else if (color.equals(MagicColor.GREEN)) {
			mana = pool[1].amount;
		} else if (color.equals(MagicColor.RED)) {
			mana = pool[2].amount;
		} else if (color.equals(MagicColor.WHITE)) {
			mana = pool[3].amount;
		} else if (color.equals(MagicColor.BLUE)) {
			mana = pool[4].amount;
		}
		return mana;
	}

	public boolean comparePool(ManaPool other) {
		boolean isGreaterThan = true;
		for (int i = 0; i < 5; i++) {
			if (other.pool[i].amount < pool[i].amount) {
				isGreaterThan = false;
			}
		}
		return isGreaterThan;
	}

	public void setColor(MagicColor color, int amount) {
		if (color.equals(MagicColor.BLACK)) {
			pool[0].amount = amount;
		} else if (color.equals(MagicColor.GREEN)) {
			pool[1].amount = amount;
		} else if (color.equals(MagicColor.RED)) {
			pool[2].amount = amount;
		} else if (color.equals(MagicColor.WHITE)) {
			pool[3].amount = amount;
		} else if (color.equals(MagicColor.BLUE)) {
			pool[4].amount = amount;
		}
	}

	/**
	 * 
	 * @param color
	 * @param amount
	 *            if(amount == -1) subtract all mana of that color
	 */
	public void subtractColor(MagicColor color, int amount) {
		if (color.equals(MagicColor.BLACK)) {
			pool[0].amount -= amount;
		} else if (color.equals(MagicColor.GREEN)) {
			pool[1].amount -= amount;
		} else if (color.equals(MagicColor.RED)) {
			pool[2].amount -= amount;
		} else if (color.equals(MagicColor.WHITE)) {
			pool[3].amount -= amount;
		} else if (color.equals(MagicColor.BLUE)) {
			pool[4].amount -= amount;
		}
	}

	public void subtractPool(ManaPool cost) {
		for (int i = 0; i < 5; i++) {
			if (cost.pool[i].amount == -1) {
				pool[i].amount = 0;
			} else {
				pool[i].amount -= cost.pool[i].amount;
			}
		}
	}

	public void addPool(ManaPool added) {
		for (int i = 0; i < 5; i++) {
			pool[i].amount += added.pool[i].amount;
		}
	}
}
